﻿<?php
//判断是否已经关注微信公众号
function is_attention($openid){
	$access_token = get_access_token();
	$subscribe_msg = 'https://api.weixin.qq.com/cgi-bin/user/info?access_token='.$access_token.'&openid='.$openid;

	$result = file_get_contents($subscribe_msg);
	$subscribe = json_decode($result);
	$zyxx = $subscribe->subscribe;
	if ($zyxx !== 1) {
		return 0;
	}else{
		return 1;
	}
}

// 获取access_token 两小时有效
function get_access_token(){
	$appid = config('admin.appid');
	$appsecret = config('admin.appsecret');
	$url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='.$appid.'&secret='.$appsecret;
	$rurl = file_get_contents($url);
	$rurl = json_decode($rurl,true);
	if(array_key_exists('errcode',$rurl)){
		return false;
	}else{
		$access_token = $rurl['access_token'];
		return $access_token;
	}
}